package File;

import java.io.*;
import java.util.Scanner;

//复制文件
public class Demo2 {
    public static void main(String[] args) throws IOException {
        System.out.println("输入你要复制的文件的路径：");
        Scanner scan = new Scanner(System.in);
        String cloneFile = scan.nextLine();
        File file = new File(cloneFile);
        if(!file.isFile()) {
            System.out.println("输入的不是文件或者文件不存在");
            return;
        }
        System.out.println("请输入你要复制到的路径：");
        String path = scan.nextLine();
        File directory = new File(path);
        if(!directory.getParentFile().isDirectory()) {
            System.out.println("你输入的不是路径或者该路径不存在...");
            return;
        }
        InputStream inputStream = new FileInputStream(file);
        OutputStream outputStream = new FileOutputStream(directory);
        byte[] bytes = new byte[4096];
        while(true) {
            int n = inputStream.read(bytes);
            if(n == -1) {
                break;
            }
            outputStream.write(bytes,0,n);
        }
        System.out.println("复制成功");
    }
}
